import data from './js/data.js';
import './css/index.css';
let h1 = document.querySelector('h1');
let btn = document.querySelector('button');
let p = document.querySelector('p');
let num = 0;
let timer = null;
let isRunning = false;

function startRandom() {
  if (!isRunning) {
    timer = setInterval(() => {
      num = Math.floor(Math.random() * data.length);
      h1.innerText = `@ ${data[num]}`;
    });
    isRunning = true;
    btn.innerText = '暂停';
  } else {
    clearInterval(timer);
    isRunning = false;
    btn.innerText = '继续';
    p.innerText += '@' + data[num] + ' ';
    data.splice(num, 1);
  }
}
btn.addEventListener('click', () => {
  if (data.length === 0) {
    h1.innerText = '没有小丑了';
    btn.disabled = true;
    return;
  }
  startRandom();
});
